﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Runtime.Remoting.Messaging;

namespace Learn.Remoting.Server
{
    public class MyRemoteObject : MarshalByRefObject 
    {
        int i = 0;

        public MyRemoteObject()
        {
            //this.i = i;
            Console.WriteLine("激活");
        }

        public int Add(int num1, int num2)
        {
            return num1 + num2;
        }

        public int Count()
        {
            return ++i;
        }

        #region
        private MBV _mbv;
        private MBR _mbr;
        
        public MBV GetMBV()
        {
            return new MBV(100);
        }

        public MBR GetMBR()
        {
            return new MBR(200);
        }

        public void SetMBV(MBV mbv)
        {
            this._mbv = mbv;
        }

        public int UseMBV()
        {
            return this._mbv.Data;
        }

        public void SetMBR(MBR mbr)
        {
            this._mbr = mbr;
        }

        public int UseMBR()
        {
            return this._mbr.Data;
        }
#endregion

        public DataSet Method(DataSet ds)
        {
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                dr["test"] = dr["test"] + "_ok";
            }
            return ds;
        }

        public int ALongTimeMethod(int a, int b, int time)
        {
            Console.WriteLine("异步方法开始");
            System.Threading.Thread.Sleep(time);
            Console.WriteLine("异步方法结束");
            return a + b;
        }

        [OneWay]
        public void ALongTimeMethodOneWay(int time)
        {
            Console.WriteLine("异步方法开始");
            System.Threading.Thread.Sleep(time);
            Console.WriteLine("异步方法结束");
        }
    }
}
